//
//  UIImageView+Extension.swift
//  SLQuickReader
//
//  Created by 孙林 on 2017/8/10.
//  Copyright © 2017年 ALin. All rights reserved.
//

import UIKit.UIImageView
import Kingfisher

extension UIImageView{
    open func setImageWithUrl(_ url: String?, placeHolder: String?) {
        var place: UIImage?
        if placeHolder != nil {
            place = Image(named: placeHolder!)
        }
        
        guard var imgurl = url else {
            return
        }
        
        if !imgurl.contains(BaseImgApi){
            imgurl = BaseImgApi + imgurl
        }
        kf.setImage(with: URL(string: imgurl), placeholder: place, options: nil, progressBlock: nil, completionHandler: nil)
    }
}

extension UIImage{
    class func imageWithcolor(_ color: UIColor) -> UIImage {
        let rect = CGRect(x: 0, y: 0, width: 1.0, height: 1.0)
        UIGraphicsBeginImageContext(rect.size)
        let context = UIGraphicsGetCurrentContext()!
        context.setFillColor(color.cgColor)
        context.fill(rect)
        let image = UIGraphicsGetImageFromCurrentImageContext()!
        UIGraphicsEndImageContext()
        return image
    }
}
